import { Button, Form, Input, NavBar } from 'antd-mobile'
import React from 'react'
import { useNavigate } from 'react-router-dom'
import utils from '../../utils/index'
const Login = () => {
    const navigate=useNavigate()
    const onFinish = async(values) => {
     console.log(values);
     const resp=await utils.post("/login",values)
     const {data,code,message}=resp.data
     if(code === 200){
        localStorage.setItem("token",data.token)
        localStorage.setItem("userInfo",JSON.stringify(data.userInfo))
        navigate("/")
        alert("登录成功")
     }else{
        alert("登录失败")
     }
  }
    return (
        <div>
            
            <NavBar backIcon={false}>登录</NavBar>
            <Form
                onFinish={onFinish}
                footer={
                    <Button block type='submit' color='primary' size='large'>
                        登录
                    </Button>
                }
            >
                <Form.Item
                    name='username'
                    label='账号'
                    rules={[{ required: true, message: '账号不能为空' }]}
                >
                    <Input></Input>
                </Form.Item>
                <Form.Item
                    name='password'
                    label='密码'
                    rules={[{ required: true, message: '密码不能为空' }]}
                >
                    <Input></Input>
                </Form.Item>
            </Form>
        </div>
    )
}

export default Login
